package com.cubeofnine.sugar.activity.import_contact;

import com.cubeofnine.sugar.business.ContactsBusiness;
import com.cubeofnine.sugar.service.element.ReturnExportContactList;

import android.content.Context;
import android.os.Handler;
import android.util.Log;

public class ImportContactsListThread extends Thread {
	private Context context;
	private Handler handler = new Handler();

	public ImportContactsListThread(Context context) {
		super();
		this.context = context;
	}

	public String getClassName() {
		return ImportContactsListThread.class.getName();
	}

	public void run() {
		Log.i(getClassName(), "run() : Start");

		String message = "";
		ReturnExportContactList result = null;
		try {
			ContactsBusiness contactsBusiness = new ContactsBusiness(context);
			result = contactsBusiness.exportContactList();
		} catch (Exception e) {
			Log.e(getClassName(), "Error", e);
			message = "Read Contacts Error.";
		} finally {
			Log.d(getClassName(), "Finally");
			handler.post(new ImportContactsListRunnable(context, result,
					message));
		}

		Log.i(getClassName(), "run() : End");
	}
}
